package com.mikeorth.view
{
	import flash.events.MouseEvent;
	
	import mx.containers.TitleWindow;
	import mx.events.CloseEvent;
	import mx.events.DragEvent;
	import mx.events.ResizeEvent;
	import mx.managers.PopUpManager;
	
	public class PopupBase extends TitleWindow
	{
		public var keepCentered:Boolean = true;
		
		private var sizeChanged:Boolean = false;
		
		public function PopupBase()
		{
			showCloseButton = true;
			addEventListener(CloseEvent.CLOSE, onClose);
			addEventListener(ResizeEvent.RESIZE, onResize);
			this.styleName = "events";
		}
		
		protected function onClose(event:CloseEvent):void
		{
			PopUpManager.removePopUp(this);
		}
		/**
		 * Centers the container on a <code>ResizeEvent</code> if needed.
		 * @param event ResizeEvent
		 * 
		 */		
		protected function onResize(event:ResizeEvent):void
		{
			if (keepCentered)
			{
				x = stage.width/2 - width/2;
				y = stage.height/2 - height/2;
			}
		}
		
		/**
		 * Overrides the Panel function that handles dragging when the container
		 * is used as a PopUp - do not call super.startDragging().
		 */  		
		override protected function startDragging(event:MouseEvent):void
		{
			event.preventDefault();
		}
		
	}
}